< previous page page_303 next page >

Page 303
0303-01.gif
Figure 10.26
A Sierpinski gasket.
e10a6a0a59f035e870d90cca05b85fce.gif
    Y As Long 
End Type 
Private Declare Function Polygon Lib "gdi32" ( _ 
    ByVal hdc As Long, lpPoint As POINTAPI, _ 
    ByVal nCount As Long) As Long 

' Draw a complete Sierpinski gasket. 
Private Sub SierpinskiGasket(ByVal depth As Integer, _ 
    ByVal x1 As Single, ByVal y1 As Single, _ 
    ByVal x2 As Single, ByVal y2 As Single, _ 
    ByVal x3 As Single, ByVal y3 As Single) 
Dim points(1 To 3) As POINTAPI 

    ' Erase the picture. 
    picCanvas.Line (0, 0)- _ 
        (picCanvas.ScaleWidth, picCanvas.ScaleHeight), _ 
        picCanvas.BackColor, BF 

    ' Draw the main filled triangle. 
    picCanvas.AutoRedraw = True 
    picCanvas.FillStyle = vbFSSolid 
    picCanvas.FillColor = vbBlack 
    points(1).X = x1 
    points(1).Y = y1 
    points(2).X = x2 
    points(2).Y = y2 
    points(3).X = x3 
    points(3).Y = y3 
    Polygon picCanvas.hdc, points(1), 3 

    ' If depth > 0, call SierpinskiErase to
    ' erase the center of this triangle.
    If depth >= 0 Then
       picCanvas.FillColor = picCanvas.BackColor 
       SierpinskiErase depth, x1, y1, x2, y2, x3, y3 
    End If

 
< previous page page_303 next page >